"""
通过chroma客户端。连接chroma数据库
"""
import chromadb
from langchain_chroma import Chroma
from my_huggingface.ModelScopeEmbeddings import ModelScopeEmbeddings

# 创建开源嵌入函数 nomic-embed-text
local_model_path = "/Users/brightzhou/.cache/modelscope/hub/models/sentence-transformers/all-MiniLM-L6-v2"
embedding_function = ModelScopeEmbeddings(local_model_path, device='cpu')
# embeddings_function = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
# embeddings_function = MyOllamaEmbeddings()
## 嵌入函数

persistent_client = chromadb.PersistentClient()
collection = persistent_client.get_or_create_collection("collection_2")
collection.add(ids=["1", "2", "3"], documents=["a", "b", "c"])

langchain_chroma = Chroma(
    client=persistent_client,
    collection_name="collection_2",
    embedding_function=embedding_function
)
"""
1. 在数据库的表collections中的name字段collection_name，collection_1
2. collection.add插入了表embedding_metadata中。
"""

print("在集合中有", langchain_chroma._collection.count(), "文档")

